package com.tacuati.content;

import java.io.File;

import javax.swing.ImageIcon;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import com.tacuati.Utils;
import com.tacuati.ui.Icons;

public class PdfBook extends Item {
	public PdfBook(String path) {
		super(path);
		this.setHash(Utils.getHash(path));
		this.setTitle(FilenameUtils.removeExtension(new File(path).getName()));
		this.setFormat(Format.PDF);
	}

	@Override
	public String toJson() {
		String json = "";
		json += "\"*" + getHash() + "\"";
		return json;
	}

	@Override
	public Item copy() {
		return new PdfBook(this.getPath());
	}

	@Override
	public boolean isEditable() {
		return true;
	}
	
	@Override
	public ImageIcon getIcon() {
		return Icons.pdfIcon;
	}
	
	@Override
	public void setNodeName(String name) {
		File source = new File(getPath());
		File dest = new File(source.getParentFile() + "/" + name + ".pdf");
		source.renameTo(dest);
		this.setPath(dest.getAbsolutePath());
		this.setTitle(FilenameUtils.removeExtension(dest.getName()));
		this.setHash(Utils.getHash(dest.getAbsolutePath()));
	}
}
